import cv2
import numpy as np

def linear_transform(image, kernel_size=3):
    # 创建一个线性拉伸核
    kernel = np.ones((kernel_size, kernel_size), np.float32) / (kernel_size * kernel_size)
    # 对图像进行卷积
    filtered_image = cv2.filter2D(image, -1, kernel)
    return filtered_image

gray_img = cv2.imread('image_path', 0)  # 加载单通道灰度图像
filtered_img = linear_transform(gray_img)
cv2.imshow("Original", gray_img)
cv2.imshow("Linear Transform", filtered_img)
cv2.waitKey(0)
cv2.destroyAllWindows()